package com.git.smp.Handler;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.git.smp.Exception.SmpException;
import com.git.smp.controller.RequireApplyController;
import com.git.smp.core.ResponseMessage;

@ControllerAdvice
public class GlobalExeceptoionHandler {
	
	Logger logger = LoggerFactory.getLogger(GlobalExeceptoionHandler.class);
	
	@ExceptionHandler(SmpException.class)
	@ResponseBody
	public ResponseMessage<?> smpExeceptionHandlder(HttpServletRequest request,SmpException smpException){
		logger.error("全局错误处理",smpException);
		ResponseMessage<?> response =  new ResponseMessage<>();
		response.setCode(smpException.getErrorCode());
		response.setMessage(smpException.getErrorMessage());
		return response;
	}
	
	
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public ResponseMessage<?> smpExeceptionHandlder(HttpServletRequest request,Exception e){
		logger.error("全局错误处理",e);
		ResponseMessage<?> response =  new ResponseMessage<>();
		response.setCode("9999");
		response.setMessage(e.getMessage());
		return response;
	}

}
